<?php

class Core_Model_Design_Collection_Block_Template extends Dcmp_Model_Collection_Strong {

    public function __construct() {
        parent::__construct();
        $this->setItemClass('design/block_template');
        $this->from('{t}design_block_template', 'a')->field('a.*');
    }

    public function joinModule(){
        return $this->innerJoin('{t}global_module', 'b', 'a.module_id', 'b.id')
                    ->field('b.title', 'module_name');
    }

    public function filterBy($name, $arg) {
        switch ($name) {
            case 'moduleid':
                return $this->addParameter('moduleId', $arg)->eq('a.module_id', ':moduleId:s');
            case 'areaid':
                return $this->addParameter('areaId', $arg)->eq('a.area_id', ':areaId:s');
            case 'enabled':
                return $this->addParameter('enabled', $arg)->eq('a.enabled', ':enabled:i');
        }
        return parent::filterBy($name, $arg);
    }
}

